﻿package list;

import common.DoubleNode;
import common.Node;

public class 反转单向和双向链表 {

	public static void main(String[] args) {

	}

	public static Node reverseList(Node head) {
		if (head == null || head.next == null) {
			return head;
		}

		Node next = null;
		Node pre = null;
		while (head != null) {
			next = head.next;
			head.next = pre;
			pre = head;
			head = next;
		}
		return pre;
	}

	/**
	 * 反转双向链表
	 * 
	 * @param head
	 * @return
	 */
	public static DoubleNode removeList(DoubleNode head) {
		DoubleNode pre = null;
		DoubleNode next= null;
		while(head!=null){
			next = head.next;
			head.next = pre;
			head.last= next;
			pre = head;
			head = next;
		}
		return pre;
	}
}
